<?php

class Activity extends Base_Controller
{
    private $conn;
    public function __construct()
    {
        parent::__construct();
        $this->load->model('Activity_model');
        $this->conn = getRedis();
        $this->conn->selectDb(0);
    }
    //  * * * * * /usr/bin/php /var/www/html/iblog/index.php job/Activity/test
    public function test()
    {
        $this->Activity_model->commonInsert('jobtest',['init_time'=>date('Y-m-d H:i:s',time())]);
    }

    //将文章浏览量从redis中更新到数据库中
    //40 17 * * * /usr/bin/php /var/www/html/iblog/index.php job/Activity/pageView
    public function pageView()
    {
        $key = "articleViewRank";
        $data = $this->conn->zRevRange($key, 0, -1, true);
        //$k 为文章id,$v为浏览量
        foreach ($data as $k => $v) {
            $this->Activity_model->commonUpdate('article', ['pageViews' => $v], ['id' => $k]);
        }
    }
}
